<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>模板</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    html, body {
      width: 100%;
      height: 100%;
      display: flex;
      place-content: center;
      place-items: center;
    }
  </style>
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
  <div id="app">
    <input type="text" v-model="text">
    <p>{{ text }}</p>
  </div>
  <script>
    const { customRef } = Vue

    const debounceRef = (value, delay = 1000) => {
      let timer
      return customRef((track, trigger) => {
        return {
          get() {
            track()
            return value
          },
          set(newValue) {
            clearTimeout(timer)
            timer = setTimeout(() => {
              value = newValue
              trigger()
            }, delay)
          }
        }
      })
    }

    const app = Vue.createApp({
      setup() {
        const text = debounceRef('')
        return {
          text
        }
      }
    })
    app.mount('#app')
  </script>
</body>
</html>